package sg.edu.nus.iss.jass.persistence;

import java.util.List;

import sg.edu.nus.iss.jass.datastore.BaseDAO;
import sg.edu.nus.iss.jass.datastore.exception.DataStoreException;
import sg.edu.nus.iss.jass.datastore.impl.Selector;
import sg.edu.nus.iss.jass.privilege.User;
import sg.edu.nus.iss.jass.util.Util;


/**
 * To authenticate the users
 * 
 * @author Daniel
 *
 */
public class UserDAO extends BaseDAO {

	/**
	 * To add jobSeeker
	 * @param user
	 * @throws DataStoreException
	 */
	public void addUser(User user) throws DataStoreException {
		save(user);
	}

	/**
	 * Get a user
	 * 
	 * @param userId
	 * @return
	 * @throws DataStoreException
	 */
	public User getUserByUserId(String userId) throws DataStoreException {
		List<User> userList = null;
		User result = null;
		try {
			userList = select(User.class, (new Selector()).eq("username", userId.toLowerCase()));
		} catch(DataStoreException e) {
			e.printStackTrace();
		}
		if (!Util.isEmpty(userList)) {
			result = userList.get(0);
		}
		return result;
	}
	

}
